/*

Compile:
```
g++ module.cpp test_module.cpp -o test_module -I../.. -I../../Svar -ldl
```

*/

#include <iostream>
#include "Svar/Svar.h"

using namespace std;

int main(int argc, char *argv[])
{
    svar.parseMain(argc, argv);

    cout << "svar = " << svar << "\n";

    sv::Svar sm = svar;
    
    cout << "svar['sample'] = " << sm << "\n";
    
    int r = sm["add"](1, 2).castAs<int>();
    printf("add(1, 2) = %d\n", r);

    r = sm["times"](2, 3).as<int>();
    printf("times(2,3) = %d\n", r);
    
    return 0;
}


int times(int a, int b)
{
    return a*b;
}

// define module in main program, and call it directly
REGISTER_SVAR_MODULE(test)
{
    svar["__name__"]="test_module";
    svar["__doc__"]="This is a test module to show call Svar module directly.";
    svar["times"]=times;
}
